package com.smarttiger.zero.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;

import javax.sql.DataSource;

/**
 * Created by zhouzhengwei on 2021/10/21.
 */
@Configuration
public class DataSourceConfige {



    @Bean("dataSource")
    @Order(1)
    @ConfigurationProperties(prefix = "spring.datasource")
    @Primary
    public DataSource getDataSource(){
        return new DruidDataSource();
    }

    @Bean("dataSource2")
    @Order(2)
    public DataSource getDataSource2(){
        DruidDataSource ds2 = new DruidDataSource();
        ds2.setUrl("jdbc:h2:mem:h2test");
        ds2.setUsername("sa");
        ds2.setPassword("sa");
        ds2.setDriverClassName("org.h2.Driver");
        return ds2;
    }
}
